package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.vo.PChatDetailsVo;
import com.ruoyi.system.domain.bo.PChatDetailsBo;
import com.ruoyi.system.service.IPChatDetailsService;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

/**
 * 聊天详情Controller
 *
 * @author ruoyi
 * @date 2022-08-22
 */
@Validated
@Api(value = "聊天详情控制器", tags = {"聊天详情管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/chatDetails")
public class PChatDetailsController extends BaseController {

    private final IPChatDetailsService iPChatDetailsService;

    /**
     * 查询聊天详情列表
     */
    @ApiOperation("查询聊天详情列表")
    @SaCheckPermission("system:chatDetails:list")
    @GetMapping("/list")
    public TableDataInfo<PChatDetailsVo> list(PChatDetailsBo bo, PageQuery pageQuery) {
        return iPChatDetailsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出聊天详情列表
     */
    @ApiOperation("导出聊天详情列表")
    @SaCheckPermission("system:chatDetails:export")
    @Log(title = "聊天详情", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PChatDetailsBo bo, HttpServletResponse response) {
        List<PChatDetailsVo> list = iPChatDetailsService.queryList(bo);
        ExcelUtil.exportExcel(list, "聊天详情", PChatDetailsVo.class, response);
    }

    /**
     * 获取聊天详情详细信息
     */
    @ApiOperation("获取聊天详情详细信息")
    @SaCheckPermission("system:chatDetails:query")
    @GetMapping("/{id}")
    public R<PChatDetailsVo> getInfo(@ApiParam("主键")
                                     @NotNull(message = "主键不能为空")
                                     @PathVariable("id") Long id) {
        return R.ok(iPChatDetailsService.queryById(id));
    }

    /**
     * 新增聊天详情
     */
    @ApiOperation("新增聊天详情")
    @SaCheckPermission("system:chatDetails:add")
    @Log(title = "聊天详情", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PChatDetailsBo bo) {
        return toAjax(iPChatDetailsService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改聊天详情
     */
    @ApiOperation("修改聊天详情")
    @SaCheckPermission("system:chatDetails:edit")
    @Log(title = "聊天详情", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PChatDetailsBo bo) {
        return toAjax(iPChatDetailsService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除聊天详情
     */
    @ApiOperation("删除聊天详情")
    @SaCheckPermission("system:chatDetails:remove")
    @Log(title = "聊天详情", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@ApiParam("主键串")
                                       @NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iPChatDetailsService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
